import 'dart:convert';

import 'package:http/http.dart' as http;

import '../model/travel_model.dart';


//旅拍页接口
Map Params = {
    "districtId": -1,
    "groupChannelCode": "RX-OMF",
    "type": null,
    "lat": -180,
    "lon": -180,
    "locatedDistrictId": 0,
    "pagePara": {
      "pageIndex": 1,
      "pageSize": 10,
      "sortType": 9,
      "sortDirection": 0
    },
    "imageCutType": 1,
    "head": {'cid': "09031014111431397988"},
    "contentType": "json"
};
class TravelDao{
  static Future<TravelModel> fetch(
      String url, String groupChannelCode, int pageIndex, int pageSize
      ) async{
    Map paramsMap = Params['pagePara'];
    paramsMap['pageIndex'] = pageIndex;
    paramsMap['pageSize'] = pageSize;
    Params['groupChannelCode'] = groupChannelCode;
    Uri uri = Uri.parse(url);
    final response = await http.post(uri,body:jsonEncode(Params));
    //数据加载成功 显示数据
    if(response.statusCode == 200){
      Utf8Decoder utf8decoder = Utf8Decoder();
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return TravelModel.fromJson(result);
    }else{
      //在失败时 显示加载失败
      throw Exception('请求旅拍界面失败');
    }
  }
}